package org.example.springmessage.service.impl;

import org.example.springmessage.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class MyUserDetailService implements UserDetailsService {

    @Autowired
    private UserService userService;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        System.out.println(username);
        org.example.springmessage.domain.User login = userService.login(username);
        UserDetails userDetails = User.withUsername(login.getUsername()).password(login.getPassword()).authorities(String.valueOf(login.getId())).build();
        return userDetails;
    }
}
